import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JSeparator;
import javax.swing.JTextField;
import javax.swing.WindowConstants;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class DlgProfesor extends javax.swing.JDialog {
	private static final long serialVersionUID = -4255928986140712672L;
	
	private JButton btnSalir;
	private JButton btnCancelar;
	private JButton btnAsignar;
	private JTextField txtNombre;
	private JTextField txtTitulo;
	private JLabel lblTitulo;
	private JLabel lblCedula;
	private JTextField txtCedula;
	private JLabel lblNombre;
	private JLabel lblApellido;
	private JTextField txtApellido;
	private JSeparator jSeparator1;
	
	private Seccion seccion;
	
	private DlgProfesor dlgp;

	/**
	* Auto-generated main method to display this JDialog
	*/
	/*public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				JFrame frame = new JFrame();
				DlgProfesor inst = new DlgProfesor(frame);
				inst.setVisible(true);
			}
		});
	}*/
	
	public DlgProfesor(JFrame frame,Seccion secc) {
		super(frame);
		dlgp = this;
		this.setResizable(false);
		this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
		seccion=secc;
		initGUI();
	}
	
	private void initGUI() {
		try {
			{
				getContentPane().setLayout(null);
				this.setTitle("Asignar Profesor");
				this.setModal(true);
				{
					btnSalir = new JButton();
					getContentPane().add(btnSalir);
					btnSalir.setText("Salir");
					btnSalir.setBounds(257, 222, 84, 21);
					btnSalir.addActionListener(new ActionListener() {
						public void actionPerformed(ActionEvent evt) {
							dlgp.dispose();
						}
					});
				}
				{
					btnCancelar = new JButton();
					getContentPane().add(btnCancelar);
					btnCancelar.setText("Restablecer");
					btnCancelar.setBounds(137, 222, 88, 21);
					btnCancelar.addActionListener(new ActionListener() {
						public void actionPerformed(ActionEvent evt) {
							Reestablecer();
						}
					});
				}
				{
					btnAsignar = new JButton();
					getContentPane().add(btnAsignar);
					btnAsignar.setText("Asignar");
					btnAsignar.setBounds(36, 222, 81, 20);
					btnAsignar.addActionListener(new ActionListener() {
						public void actionPerformed(ActionEvent evt) {
							if(ValidarCampo())
							{
								String ced = txtCedula.getText();
								
								/*if (seccion.buscarEstudiante(ced) != null){
									
									
									JOptionPane.showMessageDialog(null, "El Estudiante Ya Esta Inscrito","Informacion",JOptionPane.INFORMATION_MESSAGE);
									Reestablecer();
									return;
									
								}*/
								String nom = txtNombre.getText();
								String ape = txtApellido.getText();
								String tit = txtTitulo.getText();
								
								
								Profesor p = new Profesor(ced, nom,ape,tit);
								
								seccion.setProfesor(p);
								JOptionPane.showMessageDialog(null, "Profesor Asignado","Informacion",JOptionPane.INFORMATION_MESSAGE);
								Reestablecer();
							}
						}
					});
				}
				{
					jSeparator1 = new JSeparator();
					getContentPane().add(jSeparator1);
					jSeparator1.setBounds(0, 192, 392, 8);
				}
				{
					txtApellido = new JTextField();
					getContentPane().add(txtApellido);
					txtApellido.setText("");
					txtApellido.setBounds(67, 97, 158, 21);
				}
				{
					lblApellido = new JLabel();
					getContentPane().add(lblApellido);
					lblApellido.setText("Apellido:");
					lblApellido.setBounds(24, 100, 41, 14);
				}
				{
					txtNombre = new JTextField();
					getContentPane().add(txtNombre);
					txtNombre.setText("");
					txtNombre.setBounds(67, 56, 158, 21);
				}
				{
					lblNombre = new JLabel();
					getContentPane().add(lblNombre);
					lblNombre.setText("Nombre:");
					lblNombre.setBounds(24, 59, 41, 14);
				}
				{
					txtCedula = new JTextField();
					getContentPane().add(txtCedula);
					txtCedula.setBounds(67, 15, 88, 20);
				}
				{
					lblCedula = new JLabel();
					getContentPane().add(lblCedula);
					lblCedula.setText("Cedula:");
					lblCedula.setBounds(24, 18, 39, 13);
				}
				{
					lblTitulo = new JLabel();
					getContentPane().add(lblTitulo);
					lblTitulo.setText("Titulo:");
					lblTitulo.setBounds(24, 135, 41, 14);
				}
				{
					txtTitulo = new JTextField();
					getContentPane().add(txtTitulo);
					txtTitulo.setText("");
					txtTitulo.setBounds(67, 132, 158, 21);
				}
			}
			setSize(400, 300);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	public boolean ValidarCampo()
	{
		if(txtCedula.getText().equals(""))
		{
		   JOptionPane.showMessageDialog(null, "Ingrese una cedula","Campo Vacio",JOptionPane.INFORMATION_MESSAGE);
		   return false;
		}	else if(txtNombre.getText().equals(""))
		       {
				JOptionPane.showMessageDialog(null, "Ingrese un nombre","Campo Vacio",JOptionPane.INFORMATION_MESSAGE);	
				return false;
		       }
				else if(txtApellido.getText().equals("")){
			
					JOptionPane.showMessageDialog(null, "Ingrese un apellido","Campo Vacio",JOptionPane.INFORMATION_MESSAGE);
					return false;
				}
				else if(txtTitulo.getText().equals("")){
					
					JOptionPane.showMessageDialog(null, "Ingrese un titulo","Campo Vacio",JOptionPane.INFORMATION_MESSAGE);
					return false;
				}
				else return true;
	}
	public void Reestablecer(){
		txtCedula.setText("");
		txtNombre.setText("");
		txtApellido.setText("");
		txtTitulo.setText("");
		
	}
}
